//-----------------------scan the page and grab anything we want to log	
function parseandlog()
	{
	// message logic here...
	if (document.body.innerHTML.indexOf('message_body') != -1)
		{
		var boxes = document.getElementById(SCRIPT.appID+'_content_row').getElementsByTagName('span');
		if(boxes.length>0)
			{
			var messagebox = boxes[0];
			if(messagebox.innerHTML.indexOf('Someone has invited you to join their Crew') != -1)
				{
				if(boxes[1].innerHTML.indexOf('New') != -1)
					{
					messagebox = boxes[2];
					}
				else
					{
					messagebox = boxes[1];
					}
				}
			if(messagebox.innerHTML.indexOf('Attack Skill by 1.') != -1)
				{
				addToLog("Attack Upgraded by 1");
				}
			else if(messagebox.innerHTML.indexOf('Defense Skill by 1.') != -1)
				{
				addToLog("Defense Upgraded by 1");
				}
			else if(messagebox.innerHTML.indexOf('Energy by 1.') != -1)
				{
				addToLog("Energy Upgraded by 1");
				}
			else if(messagebox.innerHTML.indexOf('Health by 1.') != -1)
				{
				addToLog("Health Upgraded by 1");
				}
			else if(messagebox.innerHTML.indexOf('Strength by 1.') != -1)
				{
				addToLog("Strength Upgraded by 1");
				}
			else if (messagebox.innerHTML.indexOf('You Win!') != -1)
				{
				winCounter++;
				GM_setValue('winCounter', winCounter);
				addToLog("You won a fight");
				}
			else if (messagebox.innerHTML.indexOf('You Win!') != -1)
				{
				lossCounter++;
				GM_setValue('lossCounter', lossCounter);
				addToLog("You lost a fight");
				}
			else if (messagebox.innerHTML.indexOf('opponent is already') != -1 && messagebox.innerHTML.indexOf('too weak') != -1) //this means we tried to fight someone below 20 health
				{
				}
			else if (messagebox.innerHTML.indexOf('_job_again') != -1)//this means a mission was performed
				{
				}
			else if (messagebox.innerHTML.indexOf('just gave') != -1 && messagebox.innerHTML.indexOf('Pet') != -1) //this means we fed our pet
				{
				}
			else if (messagebox.innerHTML.indexOf('You just bought') != -1)
				{
				var item = messagebox.innerHTML.split('You just bought')[1].split('for')[0];
				addToLog("You just bought " + item);
				}
			else if(messagebox.innerHTML.indexOf('Ye successfully purchased') != -1)
				{
				var island = messagebox.innerHTML.split('Ye successfully purchased ')[1];
				island = island.split('.')[0];
				addToLog("Ye successfully purchased " + island);
				}
			else if(messagebox.innerHTML.indexOf('Rare Ability') != -1)
				{
				var ability = messagebox.innerHTML.split('bold;">')[1].split('</span>')[0];
				addToLog("acquired Rare Ability " + ability);
				}
			else if(messagebox.innerHTML.indexOf('Ye dug up') != -1)
				{
				var deposit = messagebox.innerHTML.split('blood.gif">')[1];
				deposit = deposit.replace(",","");
				deposit = deposit.replace(",","");
				deposit = parseInt(deposit);
				addToLog("withrew " + deposit);
				}
			else if(messagebox.innerHTML.indexOf('buried and stored safely') != -1)
				{
				var deposit = messagebox.innerHTML.split('blood.gif">')[1];
				deposit = deposit.replace(",","");
				deposit = deposit.replace(",","");
				deposit = parseInt(deposit);
				addToLog("deposit " + deposit);
				}
			else if(messagebox.innerHTML.indexOf('more health') != -1)
				{
				//The brothel massage gave ye 57 more health for 9,120.
				var addHealth = messagebox.innerHTML.split('gave ye')[1].split('more health')[0];
				var cost = 0;
				if(messagebox.innerHTML.indexOf('blood.gif">') != -1)
					{
					cost = messagebox.innerHTML.split('blood.gif">')[1];
					}
				cost	 = cost.replace(",","");
				cost	 = cost.replace(",","");
				cost	 = parseInt(cost	);
				addToLog("health +"+ addHealth + " for " + cost	);
				}
			else if(messagebox.innerHTML.indexOf('Buy items at the Armory Page') != -1)
				{
				GM_setValue('autoMission', '');
				addToLog('Unable to resume Auto-mission. You seem to be missing a required buyable item. Disabling...');
				document.location = 'http://apps.facebook.com/'+SCRIPT.name+'/index.php';
				} 
			else if(messagebox.innerHTML.indexOf('This is a loot drop, and cannot be bought.') != -1)
				{ 
				GM_setValue('autoMission','');
				addToLog('Unable to resume Auto-mission. You seem to be missing a required loot item. Disabling...');
				document.location = 'http://apps.facebook.com/'+SCRIPT.name+'/index.php';
				}
			//else alert(messagebox.innerHTML);
			}
		}
	}
	
/*
			else if(messagebox.innerHTML.indexOf('Ye fought with') != -1)
				{
				if(GM_getValue('freshMeat', '') != "checked")
					{
					var user = messagebox.innerHTML.split('user=')[1];
					var cost = 0;
					if(boxes.length!=13)
						{
						if(boxes[6].innerHTML.indexOf('found')!= -1)
							{
							addToLog("found "+ boxes[6].innerHTML.split('found ')[1].split('while fighting ')[0]);
							}
						if(boxes[9].innerHTML.indexOf('blood.gif">') != -1)
							{
							cost = boxes[9].innerHTML.split('blood.gif">')[1];
							}
						cost = cost.replace(",","");
						cost = cost.replace(",","");
						if(boxes[9].innerHTML.indexOf('WON') != -1)
							{
							addToLog("fight "+ parseInt(user) + " WON " +parseInt(cost));
							}
						else
							{
							addToLog("fight "+ parseInt(user) + " LOST " +parseInt(cost));
							}
						}
					else
						{
						if(boxes[6].innerHTML.indexOf('blood.gif">') != -1)
							{
							cost = boxes[6].innerHTML.split('blood.gif">')[1];
							}
						cost = cost.replace(",","");
						cost = cost.replace(",","");
						if(boxes[6].innerHTML.indexOf('WON') != -1)
							{
							addToLog("fight "+ parseInt(user) + " WON " +parseInt(cost));
							}
						else
							{
							addToLog("fight "+ parseInt(user) + " LOST " +parseInt(cost));
							}
						}
					}
				}
			else if(messagebox.innerHTML.indexOf('Your opponent is already dead or too weak to fight') != -1)
				{
				var opponents = GM_getValue('fightList', '').split("\n");
				var opponentList="";
				for (var i=1;i<opponents.length;i++)
					{
					opponentList = opponentList+ opponents[i]+"\n";
					}
				opponentList = opponentList + opponents[0];
				GM_setValue('fightList', opponentList);
				}
			else if(messagebox.innerHTML.indexOf('You cannot fight a member of your Clan') != -1)
				{
				if(GM_getValue('fightRandom', '') != "checked")
					{
					var opponents = GM_getValue('fightList', '').split("\n");
					var opponentList="";
					for (var i=1;i<opponents.length;i++)
						{
						opponentList = opponentList+ opponents[i]+"\n";
						}
					GM_setValue('fightList', opponentList);
					}
				}
*/